package com.huiyujiaoyu.powertime.ui.my;


import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.huiyujiaoyu.base.BaseActivity;
import com.huiyujiaoyu.http.HttpApi;
import com.huiyujiaoyu.http.HttpMethods;
import com.huiyujiaoyu.powertime.R;
import com.huiyujiaoyu.powertime.model.UserInfoBean;
import com.huiyujiaoyu.util.ActivityUtil;
import com.huiyujiaoyu.widget.LlkjToolBar;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;


public class UpdateNiceNameActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    LlkjToolBar mToolbar;
    @BindView(R.id.et_nikaname)
    EditText mEtNikaname;
    @BindView(R.id.btn_save)
    Button mBtnSave;

    private Map<String, Object> params;
    private String name;
    public static void launch(Context context) {
        ActivityUtil.startActivity(context, UpdateNiceNameActivity.class);
    }
    @Override
    protected void initView() {
        setToolbar(mToolbar);
        mToolbar.setToolBar("修改用户名", true, "", R.mipmap.icon_titlebar_back, false, "", LlkjToolBar.isNull);
        mEtNikaname.setText(UserInfoBean.getInstance().getNickName());
    }


    @Override
    protected void initListener() {

    }
    @Override
    protected void initData() {

    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_updata_nickname;
    }


    @OnClick({R.id.btn_save})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_save:
                name = mEtNikaname.getText() + "";
                if (params == null) {
                    params = new HashMap<>();
                }
                params.put("nickname", name);
                HttpMethods.getInstance().update(mContext, getComp(), this, params);
                break;
        }
    }

    @Override
    public void onNext(Object o, int httpcode) {
        super.onNext(o, httpcode);
        switch (httpcode) {
            case HttpApi.HTTP_UPDATE:
                UserInfoBean.getInstance().setNickName(name);
                finish();
                break;
        }
    }
}
